package com.web08.session;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;

/**
 * @author wzm
 * @create 2023-11-13 15:30
 * project_name:web2310
 * @Description
 */

@WebServlet("/sessionServlet1")
public class SessionServlet1 extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       //获取session对象 存储值
        HttpSession session = req.getSession();
        session.setAttribute("list","好好学习");

        //修改  需要替换同名的key 不同的值
//        session.setAttribute("list","天天向上");

        //移除session
//        session.removeAttribute("list");

        resp.sendRedirect(req.getContextPath()+"/sessionServlet2");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       doPost(req, resp);
    }
}
